let dataCont = JSON.parse(localStorage.getItem('dataCont'));
let date = new Date
console.log(date.toLocaleDateString());
console.log(dataCont);
$('#sel_3').attr('value', dataCont.b_id);
$('#sel_4').attr('value', dataCont.b_num);
$('#sel_6').attr('value', dataCont.p_num);
$('#sel_7').attr('value', date.toLocaleDateString());
$('#sel_8').attr('value', dataCont.p_remark);

function showSelCom() {
    $.ajax({
        url: '/organization/showsel_branch',
        success: (res) => {
            $('#sel_1').html(`<option value="${dataCont.b_name}" selected disabled class="sel_none">${dataCont.b_name}</option>`);
            $(res.data).each((index, item) => {
                $('#sel_1').append(`    
            <option value="${item.b_name}">${item.b_name}</option>`);
            })
        }
    })
}

function showSelCom2() {
    $.ajax({
        url: '/organization/showsel_post',
        data: {
            val: dataCont.b_name
        },
        success: (res) => {
            $('#sel_2').html(`<option value="${dataCont.p_name}" selected disabled class="sel_none">${dataCont.p_name}</option>`);
            $(res.data).each((index, item) => {
                $('#sel_2').append(`    
        <option value="${item.p_name}">${item.p_name}</option>`);
            })
        }
    })
}
$('.textarea')[0].oninput = function() {
    $(this).next().children().html(this.value.length);
}

// 编辑职业
function orgRedact() {
    let sel_2
    $('.btn_redact').click(function() {
        $('#sel_2').val() != null ? sel_2 = $('#sel_1').val() : sel_2 = dataCont.p_name;
        if (confirm('是否确定保存修改？')) {
            $.ajax({
                url: '/organization/redact',
                method: 'post',
                data: {
                    p_id: dataCont.p_id,
                    p_b_id: $('#sel_3').val(),
                    p_name: sel_2,
                    p_num: $('#sel_6').val(),
                    p_time: $('#sel_7').val(),
                    p_premark: $('#sel_8').val()
                },
                success: (res) => {
                    if (res.error) {
                        console.log(res.msg);
                        alert('带*的内容必须填写!');
                    } else {
                        alert('修改成功!');
                        window.location.replace(document.referrer)
                    }
                }
            })
        }
    })
}